import { computed } from 'vue';
import { useStore, mapState, createNamespacedHelpers, mapGetters } from 'vuex'
/**
* 映射store对应的属性（mapState｜mapGetters）
* @param mappers mapState([])｜mapGetters([])
* @returns {[propName:string]: ComputedRefImpl,...}
*/
const getStoreMap = (mappers) => {
    const store = useStore()
    const mapData = {}
    const storeStateFns = mapState(mappers)
    Object.keys(storeStateFns).forEach((item) => {
        mapData[item] = computed(storeStateFns[item].bind({ $store: store }));
    });
    return mapData;
}
/**
 * @name: 用来批量取值 moudle里面的store值
 * @msg: 
 * @return {*}
 */
// 用来批量mapstate modules里面的值
const getStoreModulesMap = (moduleName, mappers) => {
    let mapFn = createNamespacedHelpers(moduleName).mapState ;// moduleName 就是模块的名字
    const store = useStore()
    const mapData = {}
    const storeStateFns = mapFn(mappers)
    Object.keys(storeStateFns).forEach((item) => {
        mapData[item] = computed(storeStateFns[item].bind({ $store: store }));
    });
    return mapData;
}

// 用来批量mapGetters modules里面的值
const getStoreModulesGet = (moduleName, mappers) => {
    let mapFn = createNamespacedHelpers(moduleName).mapGetters ;// moduleName 就是模块的名字
    const store = useStore()
    const mapData = {}
    const storeStateFns = mapFn(mappers)
    Object.keys(storeStateFns).forEach((item) => {
        mapData[item] = computed(storeStateFns[item].bind({ $store: store }));
    });
    return mapData;
}
export { getStoreMap, getStoreModulesMap, getStoreModulesGet }